/*
 * simplelog.h
 *
 *  Created on: 2011-5-8
 *      Author: chenl
 */

#ifndef SIMPLELOG_H_
#define SIMPLELOG_H_

#include "logengine.h"
#include "common_libnamespace.h"

#include <stdarg.h>
#include <stdio.h>

CHENLIB_NAMESPACE_BEGIN

extern int32_t VWriteLog( const char* 	cszLogFilePrefix,
		  	  	  	  	  IOType		io,
		  	  	  	  	  LogLevel		enmLogLv,
		  	  	  	  	  const char*	cszFormat,
		  	  	  	  	  va_list		arg	);

class CSimpleLog : public CLogEngineBase
{
public:
	CSimpleLog(const char* cszLogPrefix)
		: io_(enmStdIO)
	{
		snprintf(szLogPrefix_, sizeof(szLogPrefix_), "%s", cszLogPrefix);
	}
	CSimpleLog(const char* cszLogPrefix, LogLevel logLevel)
		:  CLogEngineBase(logLevel), io_(enmStdIO)
	{
		snprintf(szLogPrefix_, sizeof(szLogPrefix_), "%s", cszLogPrefix);
	}
	CSimpleLog(const char* cszLogPrefix, LogLevel logLevel, IOType io)
		: CLogEngineBase(logLevel), io_(io)
	{
		snprintf(szLogPrefix_, sizeof(szLogPrefix_), "%s", cszLogPrefix);
	}
	virtual ~CSimpleLog()
	{
	}

public:
	virtual int32_t WriteLog(LogLevel enmLogLv, const char* cszFormat, ...)
	{
		if (GetLogLevel() > enmLogLv)
			return S_FALSE;
		va_list argp;
		va_start(argp, cszFormat);
		int32_t ret = VWriteLog(szLogPrefix_, io_, enmLogLv, cszFormat, argp);
		va_end(argp);
		return ret;
	}

private:
	char 		szLogPrefix_[enmMaxLogPrefixLen];
	IOType		io_;
};

CHENLIB_NAMESPACE_END

#endif /* SIMPLELOG_H_ */
